import os
import sys
import re

Be = "\x89\x50\x4e\x47"
En = "\x49\x45\x4e\x44\xae\x42\x60\x82"

fn = sys.argv[1]
con = open(fn, 'rb').read()

State = 0
Head = 0
End = 0
p = con.find(Be)
p1 = con.find(En)
print p, p1

sub = con[p:(p1+len(En))]

open("test.png", "wb").write(sub)
